<?php
class LoginAction extends Action
{
	public function login()
	{

		$id = $_POST['_id'];
		$password = $_POST['password'];
		
		$condition['password'] = $password;
		$role_dao;
		if($_POST['role'] == 'student'){
			$role_dao = M('student');
			$condition['studentid'] = $id;
		}
		else{
			$role_dao = M('admin');
			$condition['adminid'] = $id;
		}
		$result = $role_dao->where($condition)->find();
		if($result != null){
			if($_POST['role'] == 'student'){
				$_SESSION['id'] = $result['id'];
				$_SESSION['name'] = $result['name'];
				$this->redirect("Index/studentMain");
			}
			else{
				$_SESSION['admin_id'] = $result['id'];
				$_SESSION['admin_name'] = $result['name'];
				$this->redirect("Index/adminMain");
			}			
		}
		else{		
			$this->redirect('Login/loginPage');
		}
	}

    public function logout()
	{
		unset($_SESSION['id']);
		unset($_SESSION['name']);
		$this->redirect('Login/loginPage');
	}
	public function test()
	{
		echo "hello";
	}
	

}
?>